# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: team/kde <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=kde-plasma
pkgname=kwin
pkgver=5.27.10
pkgrel=0
pkgdesc="An easy to use, but flexible, composited Window Manager"
# armhf blocked by qt5-qtdeclarative
arch="all !armhf"
url="https://kde.org/plasma-desktop/"
license="GPL-2.0-or-later AND (GPL-2.0-only OR GPL-3.0-only) AND LGPL-2.1-only"
depends="
	hwdata
	kirigami2
	qt5-qtmultimedia
	qt5-qtwayland
	xwayland
	"
depends_dev="
	breeze-dev
	eudev-dev
	fontconfig-dev
	kactivities5-dev
	kcmutils5-dev
	kcompletion5-dev
	kconfig5-dev
	kconfigwidgets5-dev
	kcoreaddons5-dev
	kcrash5-dev
	kdeclarative5-dev
	kdecoration-dev
	kglobalaccel5-dev
	ki18n5-dev
	kiconthemes5-dev
	kidletime5-dev
	kinit5-dev
	kio5-dev
	knewstuff5-dev
	knotifications5-dev
	kpackage5-dev
	krunner5-dev
	kscreenlocker-dev
	kservice5-dev
	ktextwidgets5-dev
	kwayland5-dev
	kwidgetsaddons5-dev
	kwindowsystem5-dev
	kxmlgui5-dev
	lcms2-dev
	libdrm-dev
	libepoxy-dev
	libinput-dev
	libqaccessibilityclient-dev
	libxcvt-dev
	libxi-dev
	libxkbcommon-dev
	mesa-dev
	mesa-gbm
	pipewire-dev
	plasma-framework5-dev
	qt5-qtbase-dev
	qt5-qtdeclarative-dev
	qt5-qtscript-dev
	qt5-qtsensors-dev
	qt5-qtx11extras-dev
	wayland-dev
	xcb-util-cursor-dev
	xcb-util-image-dev
	xcb-util-wm-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	kdoctools5-dev
	libcap-utils
	qt5-qttools-dev
	samurai
	"
checkdepends="xvfb-run"

case "$pkgver" in
	*.90*) _rel=unstable;;
	*) _rel=stable;;
esac
_repo_url="https://invent.kde.org/plasma/kwin.git"
source="https://download.kde.org/$_rel/plasma/$pkgver/kwin-$pkgver.tar.xz"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc $pkgname-lang"
options="!check" # Broken

build() {
	# significantly reduce debug symbol size
	# use None here to not make cmake pass bare -g (-g2)
	CFLAGS="$CFLAGS -O2 -g1" CXXFLAGS="$CXXFLAGS -O2 -g1" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib
	cmake --build build
}

check() {
	xvfb-run ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# We don't ship systemd
	rm -r "$pkgdir"/usr/lib/systemd

	# kwin_wayland has CAP_SYS_NICE set. Because of this, libdbus doesn't trust the
	# environment and ignores it, causing for example keyboard shortcuts to not work
	# Remove CAP_SYS_NICE from kwin_wayland to make them work again
	setcap -r "$pkgdir"/usr/bin/kwin_wayland
}
sha512sums="
f9cfbad8eb97c26417e430424bd496bfa31f9e3c6953ab68a7cff467de8ad43bc10a764f47bd0ce3afe4d27d2cd981ba949d09ab3090dfcef9e7a77b5a918f71  kwin-5.27.10.tar.xz
"
